package com.yf.listview2;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		ListView lv_list = (ListView) findViewById(R.id.lv_list);
		lv_list.setAdapter(new MyAdapter());
	}

	private class MyAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return 5;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@SuppressLint("InflateParams")
		@SuppressWarnings("unused")
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			View view = null;

			if (convertView == null) {
				/*
				 * View.inflate方法的参数： 参数一：上下文 ; 参数二：xml布局文件的id;
				 * 参数三：inflate出来的view对象的父容器，比如LinearLayout, RelativeLayout等；
				 * 参数三：null表示只想将xml文件转换成View对象，暂时不挂载。
				 */
				view = View.inflate(MainActivity.this, R.layout.item, null);
				// 获取LayoutInflater第一种方式
				LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
				// 获取LayoutInflater第二种方式
				LayoutInflater inflater2 = getLayoutInflater();
				// 获取LayoutInflater第三种方式（见google的源代码）
				LayoutInflater inflater3 = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
			} else {
				view = convertView;
			}

			return view;
		}

	}
}
